home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / cagd_lib / cagd_loc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  6.5 KB  |  189 lines

  1. /******************************************************************************
  2. * Cagd_loc.h - header file for the CAGD library.                  *
  3. * This header is local to the library - it is NOT external.              *
  4. *******************************************************************************
  5. * Written by Gershon Elber, Mar. 90.                          *
  6. ******************************************************************************/
  7.  
  8. #ifndef CAGD_LOC_H
  9. #define CAGD_LOC_H
  10.  
  11. #include <math.h>
  12.  
  13. typedef enum TokenNumType {/* Tokens are returned by _CagdGetToken routines. */
  14.     TOKEN_EOF,
  15.     TOKEN_OPEN_PAREN,
  16.     TOKEN_CLOSE_PAREN,
  17.     TOKEN_BEZIER,
  18.     TOKEN_BSPLINE,
  19.     TOKEN_POWER,
  20.     TOKEN_CURVE,
  21.     TOKEN_SURFACE,
  22.     TOKEN_PTYPE,
  23.     TOKEN_NUM_PTS,
  24.     TOKEN_ORDER,
  25.     TOKEN_KV,
  26.     TOKEN_OTHER
  27. } TokenNumType;
  28.  
  29. #define CAGD_GEN_COPY(Dst, Src, Size) memcpy((char *) (Dst), (char *) (Src), \
  30.                          Size)
  31. #define CAGD_GEN_COPY_STEP(Dst, Src, Size, DstStep, SrcStep, Type) \
  32.             { \
  33.                 int ii; \
  34.                 Type *DstType = (Type *) Dst, \
  35.                  *SrcType = (Type *) Src; \
  36.  \
  37.                 for (ii = 0; ii < Size; ii++) { \
  38.                 *DstType = *SrcType; \
  39.                 DstType += DstStep; \
  40.                 SrcType += SrcStep; \
  41.                 } \
  42.             }
  43.  
  44.  
  45. /******************************************************************************
  46. * Some lists simplifying operators.                          *
  47. ******************************************************************************/
  48. #define CAGD_LIST_PUSH(New, List)       { (New) -> Pnext = (List); \
  49.                       (List) = (New); }
  50. #define CAGD_LIST_POP(Head, List)    { (Head) = (List); \
  51.                       (List) = (List) -> Pnext; \
  52.                       (Head) -> Pnext = NULL; }
  53. #define CAGD_LIST_LAST(Elem)        { if (Elem) \
  54.                           while ((Elem) -> Pnext) \
  55.                           (Elem) = (Elem) -> Pnext; }
  56.  
  57. /******************************************************************************
  58. * Some points/ectors simplifying operators.                      *
  59. ******************************************************************************/
  60. #define    CAGD_COPY_POINT(DstPt, SrcPt)    { (DstPt) = (SrcPt); }
  61. #define    CAGD_RESET_POINT(DstPt)     { (DstPt).Pt[0] = \
  62.                       (DstPt).Pt[1] = \
  63.                       (DstPt).Pt[2] = 0.0; }
  64. #define    CAGD_ADD_POINT(DstPt, SrcPt)    { (DstPt).Pt[0] += (SrcPt).Pt[0]; \
  65.                       (DstPt).Pt[1] += (SrcPt).Pt[1]; \
  66.                       (DstPt).Pt[2] += (SrcPt).Pt[2]; }
  67. #define    CAGD_SUB_POINT(DstPt, SrcPt)    { (DstPt).Pt[0] -= (SrcPt).Pt[0]; \
  68.                       (DstPt).Pt[1] -= (SrcPt).Pt[1]; \
  69.                       (DstPt).Pt[2] -= (SrcPt).Pt[2]; }
  70. #define    CAGD_MULT_POINT(DstPt, Scaler)  { (DstPt).Pt[0] *= (Scaler); \
  71.                       (DstPt).Pt[1] *= (Scaler); \
  72.                       (DstPt).Pt[2] *= (Scaler); }
  73.  
  74. #define    CAGD_COPY_VECTOR(DstVec, SrcVec) { (DstVec) = (SrcVec); }
  75. #define    CAGD_RESET_VECTOR(DstVec)     { (DstVec).Vec[0] = \
  76.                       (DstVec).Vec[1] = \
  77.                       (DstVec).Vec[2] = 0.0; }
  78. #define    CAGD_ADD_VECTOR(DstVec, SrcVec) { (DstVec).Vec[0] += (SrcVec).Vec[0]; \
  79.                       (DstVec).Vec[1] += (SrcVec).Vec[1]; \
  80.                       (DstVec).Vec[2] += (SrcVec).Vec[2]; }
  81. #define    CAGD_SUB_VECTOR(DstVec, SrcVec) { (DstVec).Vec[0] -= (SrcVec).Vec[0]; \
  82.                       (DstVec).Vec[1] -= (SrcVec).Vec[1]; \
  83.                       (DstVec).Vec[2] -= (SrcVec).Vec[2]; }
  84. #define    CAGD_MULT_VECTOR(DstVec, Scaler){ (DstVec).Vec[0] *= (Scaler); \
  85.                       (DstVec).Vec[1] *= (Scaler); \
  86.                       (DstVec).Vec[2] *= (Scaler); }
  87. #define    CAGD_DIV_VECTOR(DstVec, Scaler) { (DstVec).Vec[0] /= (Scaler); \
  88.                       (DstVec).Vec[1] /= (Scaler); \
  89.                       (DstVec).Vec[2] /= (Scaler); }
  90. #define CAGD_LEN_VECTOR(V)        sqrt(SQR((V).Vec[0]) + \
  91.                          SQR((V).Vec[1]) + \
  92.                          SQR((V).Vec[2]))
  93. #define CAGD_NORMALIZE_VECTOR(V)    { CagdRType __t = CAGD_LEN_VECTOR(V); \
  94.                       if (!APX_EQ(__t, 0.0)) \
  95.                           CAGD_DIV_VECTOR((V), __t); }
  96.  
  97.  
  98. #define    CAGD_COPY_UVVAL(DstUV, SrcUV) { (DstUV) = (SrcUV); }
  99. #define    CAGD_RESET_UVVAL(DstUV)     { (DstUV).UV[0] = \
  100.                       (DstUV).UV[1] = 0.0; }
  101.  
  102. /******************************************************************************
  103. * A fast macro to blend the original control polygon with the Alpha matrix.   *
  104. ******************************************************************************/
  105. #define CAGD_ALPHA_BLEND( A, Index, OrigPts, Pt ) \
  106.     { \
  107.     if (A -> ColLength[Index] == 1) \
  108.         *Pt = OrigPts[A -> ColIndex[Index]]; \
  109.     else { \
  110.         int Tmp; \
  111.  \
  112.         *Pt = 0.0; \
  113.         for (Tmp = A -> ColLength[Index] - 1; Tmp >= 0; Tmp--) { \
  114.         int Idx = A -> ColIndex[Index] + Tmp; \
  115.  \
  116.         *Pt += OrigPts[Idx] * A -> Rows[Idx][Index]; \
  117.         } \
  118.     } \
  119.     }
  120.  
  121. /* Same as CAGD_ALPHA_BLEND but Allow step for OrigPts. */
  122. #define CAGD_ALPHA_BLEND_STEP( A, Index, OrigPts, Pt, OrigPtsStep ) \
  123.     { \
  124.     if (A -> ColLength[Index] == 1) \
  125.         *Pt = OrigPts[A -> ColIndex[Index] * OrigPtsStep]; \
  126.     else { \
  127.         int Tmp; \
  128.  \
  129.         *Pt = 0.0; \
  130.         for (Tmp = A -> ColLength[Index] - 1; Tmp >= 0; Tmp--) { \
  131.         int Idx = A -> ColIndex[Index] + Tmp; \
  132.  \
  133.         *Pt += OrigPts[Idx * OrigPtsStep] * A -> Rows[Idx][Index]; \
  134.         } \
  135.     } \
  136.     }
  137.  
  138. /******************************************************************************
  139. * This macro is called when the library has detected an unrecoverable error.  *
  140. * Default action is to call CagdFatalError, but you may want to reroute this  *
  141. * to invoke your handler and recover yourself (by long jump for example).     *
  142. ******************************************************************************/
  143. #define FATAL_ERROR(Msg)    CagdFatalError(Msg)
  144.  
  145. #define INFINITY 1e6
  146.  
  147. #define W 0     /* Positions of points in Points array (see structs below). */
  148. #define X 1
  149. #define Y 2
  150. #define Z 3
  151.  
  152. #include "cagd_lib.h"             /* Include the extrenal header as well. */
  153.  
  154. #ifdef DOUBLE
  155. #define CAGD_FLOAT_READ "%lf"
  156. #else
  157. #define CAGD_FLOAT_READ "%f"
  158. #endif /* DOUBLE */
  159.  
  160. /* Declaration of extrenal variables local to the cagd library only. */
  161. extern int _CagdGlblLineCount;         /* Used to locate errors in input file. */
  162. extern CagdLin2PolyType _CagdLin2Poly;    /* Linear srf convertion to polys. */
  163.  
  164. /* Declarations of functions local to the Cagd library only. */
  165. char *_CagdGetCurveAttributes(FILE *f);
  166. char *_CagdGetSurfaceAttributes(FILE *f);
  167. void _CagdUnGetToken(char *StringToken);
  168. TokenNumType _CagdGetToken(FILE *f, char *StringToken);
  169. char *_CagdReal2Str(CagdRType R);
  170. CagdPolygonStruct *_CagdMakePolygon(CagdBType ComputeNormals,
  171.                     CagdBType ComputeUV,
  172.                         CagdPtStruct *Pt1,
  173.                     CagdPtStruct *Pt2,
  174.                     CagdPtStruct *Pt3,
  175.                     CagdVecStruct *Nl1,
  176.                     CagdVecStruct *Nl2,
  177.                         CagdVecStruct *Nl3,
  178.                     CagdUVStruct *UV1,
  179.                     CagdUVStruct *UV2,
  180.                         CagdUVStruct *UV3);
  181.  
  182. #ifdef USE_VARARGS
  183. void _CagdFprintf(FILE *f, int Indent, char *va_alist, ...);
  184. #else
  185. void _CagdFprintf(FILE *f, int Indent, char *Format, ...);
  186. #endif /* USE_VARARGS */
  187.  
  188. #endif /* CAGD_LOC_H */
  189.